import axios from 'axios'
import { Toast } from 'vant'
// 获取轮播图api 0 pc 1安卓 2苹果
const baseUrl = 'http://music.cpengx.cn'
export function getBanner (type) {
  return axios.get(`${baseUrl}/banner?type=${type}`)
}
// 获取推荐歌单
export function getMusicList (limit = 10) {
  return axios.get(`${baseUrl}/personalized?limit=${limit}`)
}
// 获取歌单详情
export function getPlaylistDetail (id) {
  return axios.get(`${baseUrl}/playlist/detail?id=${id}`)
}
// 获取歌词
export function getlyric (id) {
  return axios.get(`${baseUrl}/lyric?id=${id}`)
}
// 搜索歌曲
export function searchMusic (keyWord) {
  return axios.get(`${baseUrl}/cloudsearch?keywords=${keyWord}`)
}
// 登录 手机密码登录
export function phoneLogin (phone, password) {
  return axios.get(`${baseUrl}/login/cellphone?phone=${phone}&password=${password}`)
}
// 登录 手机验证码登录
export function phoneLogins (phone, captcha) {
  return axios.get(`${baseUrl}/login/cellphone?phone=${phone}&captcha=${captcha}`)
}
// 发送验证码
export function getSent (phone) {
  return axios.get(`${baseUrl}/captcha/sent?phone=${phone}`)
}
// 验证验证码
export function setSent (phone, captcha) {
  return axios.get(`${baseUrl}/captcha/verify?phone=${phone}&captcha=${captcha}`)
}
// 获取用户详情
export function userDetail (uid) {
  return axios.get(`${baseUrl}/user/detail?uid=${uid}`)
}
// 获取用户动态
export function userEvent (uid) {
  return axios.get(`${baseUrl}/user/event?uid=${uid}`)
}
// 判断登录状态
export function userstatus () {
  return axios.get(`${baseUrl}/login/status`)
}
// 获取推荐新音乐
export function setPersonalizedt () {
  return axios.get(`${baseUrl}/personalized/newsong`)
}
// 获取用户播放记录
export function setRecord (uid) {
  return axios.get(`${baseUrl}/user/record?uid=${uid}&type=0`)
}
// 登录退出
export function userLogout () {
  return axios.get(`${baseUrl}/logout`)
}
// 获取歌单
export function setTopPlaylist (limit, cat, before) {
  return axios.get(`${baseUrl}/top/playlist/highquality?limit=${limit}&cat=${cat}&before=${before}`)
}
// 获取标签列表
export function setTags () {
  return axios.get(`${baseUrl}/playlist/catlist`)
}
// 排行榜
export function setArtist () {
  return axios.get(`${baseUrl}/toplist/artistrtist`)
}
// 热门歌手
export function setArtists () {
  return axios.get(`${baseUrl}/top/artists?offset=0&limit=30`)
}
// 条件查询歌手
export function setArtistss (type = -1, area = -1, initial = 'a') {
  return axios.get(`${baseUrl}/artist/list?type=${type}&area=${area}&initial=${initial}`)
}
// 获取歌手详情
export function setDetail (uid) {
  return axios.get(`${baseUrl}/artist/detail?id=${uid}`)
}
// 获取歌手描述
export function setDesc (uid) {
  return axios.get(`${baseUrl}/artist/desc?id=${uid}`)
}
// 获取歌手专辑
export function setAlbum (uid) {
  return axios.get(`${baseUrl}/artist/album?id=${uid}&limit=30`)
}
// 获取歌手MV /artist/mv?id=6452
export function setMV (uid) {
  return axios.get(`${baseUrl}/artist/mv?id=${uid}`)
}
// 获取歌手单曲
export function setartists (uid) {
  return axios.get(`${baseUrl}/artists?id=${uid}`)
}
// 获取专辑详情
export function setAlbums (uid) {
  return axios.get(`${baseUrl}/album?id=${uid}`)
}
// 获取mv地址
export function setmvlist (uid) {
  return axios.get(`${baseUrl}/mv/url?id=${uid}`)
}
// 获取用户信息
export function setsubcount () {
  return axios.get(`${baseUrl}/user/subcount`)
}
// 热门搜索列表
export function setHot () {
  return axios.get(`${baseUrl}/search/hot`)
}

axios.interceptors.request.use(function (config) {
  // loading拦截器
  Toast.loading({
    message: '加载中...',
    forbidClick: true,
    loadingType: 'spinner',
    duration: 0
  })
  return config
}, function (error) {
  return Promise.reject(error)
})

axios.interceptors.response.use(function (response) {
  // 清除loading拦截器
  Toast.clear()
  return response
}, function (error) {
  return Promise.reject(error)
})
export default {
  getBanner,
  getMusicList,
  getPlaylistDetail,
  getlyric,
  searchMusic,
  phoneLogin,
  userDetail,
  userstatus,
  setPersonalizedt,
  userEvent,
  setRecord,
  userLogout,
  setTopPlaylist,
  setTags,
  setArtist,
  setArtists,
  setArtistss,
  setDetail,
  setDesc,
  setAlbum,
  setMV,
  setartists,
  setAlbums,
  setmvlist,
  setsubcount,
  phoneLogins,
  getSent,
  setSent,
  setHot
}
